#ifndef __CRAFTING_RECIPES_MANAGER_H__
#define __CRAFTING_RECIPES_MANAGER_H__

#include <cstdint>
#include <vector>
#include "nlohmann/json.hpp"
#include <unordered_map>

#include "GameSingleton.h"

namespace PocketSurvival
{
    struct CraftingRecipe
    {
        // 合成出来的物品
        int32_t resultValue = 0;
        uint32_t resultCount = 0;
        // 副产物
        int32_t remainsValue = 0;
        uint32_t remainsCount = 0;
        // 需要的玩家等级
        int32_t requiredPlayerLevel = 0;
        // 配方
        int32_t ingredients[9];
        // 数据比特位，用于区分是否方块中的Data值等数据
        int32_t ingredientsDataBit[9];
    };
    class CraftingRecipesManager : public SimpleSingletonItem
    {
        friend class SimpleSingleton;
    private:
        std::unordered_map<uint8_t, std::vector<CraftingRecipe*>> craftingRecipesMap;

    private:
        CraftingRecipesManager();
        ~CraftingRecipesManager();
        CraftingRecipesManager(const CraftingRecipesManager &) = delete;
        CraftingRecipesManager(CraftingRecipesManager &&) = delete;
        CraftingRecipesManager &operator=(const CraftingRecipesManager &) = delete;
        CraftingRecipesManager &operator=(CraftingRecipesManager &&) = delete;

        static uint8_t ArrangeRecipe(int32_t *ingredients, int32_t *outIngredients);

    public:
        void loadCraftingRecipeSource(const nlohmann::json &jsonData);
        CraftingRecipe *findCraftingRecipe(int32_t *ingredients);

        void loadGame();
    };
} // namespace PocketSurvival


#endif
